package com.slw.emergency.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.slw.emergency.entity.EmergencyDetail;
import com.slw.emergency.entity.EmergencyVillage;
import com.slw.emergency.model.RespCityDistanceModel;
import com.slw.emergency.model.RespCityModel;
import com.slw.emergency.service.EmergencyDetailService;
import com.slw.emergency.service.QueryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/emergency")
public class EmergencyController {
    @Autowired
    private QueryService queryService;

    @PostMapping("/insertDetail")
    public void insertDetail(){
        queryService.insertDetail(true);
    }

    @GetMapping("/getDetailByCity")
    @ResponseBody
    @ApiOperation(value ="根据省市名查询疫情小区", notes = "省市名")
    public List<RespCityModel> getDetailByCity(@RequestParam(value = "province") String province,@RequestParam(value = "city") String city){
        return queryService.getDetailByCity(province,city);
    }

    @GetMapping("/getDetailByCellName")
    @ResponseBody
    @ApiOperation(value ="根据小区名查询疫情小区", notes = "小区名")
    public List<RespCityModel> getDetailByCellName(@RequestParam(value = "cellName") String cellName,@RequestParam(value = "city") String city){
        return queryService.getDetailByCellName(cellName,city);
    }

    @GetMapping("/getDistanceByCity")
    @ResponseBody
    public List<RespCityDistanceModel> getDistanceByCity(@RequestParam(value = "province") String province,
                                                         @RequestParam(value = "city") String city,
                                                         @RequestParam(value = "lon") double lon,
                                                         @RequestParam(value = "lat") double lat){
        return queryService.getDistanceByCity(province,city,lon,lat);
    }

    @RequestMapping("/getSpaceChange")
    @ResponseBody
    public Map<String, Object> getSpaceChange(){
        return queryService.getSpaceChange();
    }

    /**
     * 获取访问量
     * @param request
     * @return
     */
    @GetMapping("/countVisit")
    @ResponseBody
    public String countVisit(HttpServletRequest request){
        queryService.countVisit(request);
        return "success";
    }

    @GetMapping("/getVillage")
    @ResponseBody
    public Map<String, Object> getVillage(){
        return queryService.getVillage();
    }

}
